/**
 * @project_name staff_vehicle
 * @package_name com.ssh.dao
 * @desc TODO
 * @param
 * @author jack
 * @date 2013-4-24
 * @time 下午10:23:27
 */
package com.ssh.dao;

import java.util.List;

import org.hibernate.SessionFactory;

import com.ssh.entity.DLicence;

/**
 * @author jack
 *
 */
public class DLicenceDAOImpl implements DLicenceDAOI {
	private SessionFactory sessionFactory;

	/* (non-Javadoc)
	 * @see com.ssh.dao.DLicenceDAOI#queryById(java.lang.String)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public DLicence queryById(String id) {
		// TODO Auto-generated method stub
		DLicence dLicence ;
		try{
			String hql = "from DLicence as dl where dl.id=?";
			dLicence =
					(DLicence) sessionFactory.getCurrentSession().
					createQuery(hql).setString(0, id).uniqueResult();
		}
		catch(Exception e){
			return null;
		}

		return dLicence ;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.DLicenceDAOI#updateByDL(com.ssh.entity.DLicence)
	 */
	@Override
	public DLicence updateByDL(DLicence dLicence) {
		// TODO Auto-generated method stub
		try{
			sessionFactory.getCurrentSession().update(dLicence);
		}
		catch(Exception e){
			return null ;
		}

		return dLicence;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.DLicenceDAOI#deleteById(java.lang.String)
	 */
	@Override
	public int deleteById(String id) {
		// TODO Auto-generated method stub
		int num ;
		try{
			String hql = "delete DLicence as dl where dl.id=?";
			num = sessionFactory.getCurrentSession().createQuery(hql).setString(0, id).executeUpdate();
		}
		catch(Exception e){
			return 0 ;
		}
		return num;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.DLicenceDAOI#addDLicence(com.ssh.entity.DLicence)
	 */
	@Override
	public DLicence addDLicence(DLicence dLicence) {
		// TODO Auto-generated method stub
		try{
			sessionFactory.getCurrentSession().save(dLicence);
			
		}
		catch(Exception e){
			e.printStackTrace();
			return null;
		}
		return dLicence ;

	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.DLicenceDAOI#addDLicenceList(java.util.List)
	 */
	@Override
	public int addDLicenceList(List<DLicence> dLicenceList) {
		// TODO Auto-generated method stub
		int length = dLicenceList.size();
		try{
			for(int i=0;i<length;i++)
				addDLicence(dLicenceList.get(i));
		}
		catch(Exception e){
			return 0;
		}
		return length;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.DLicenceDAOI#queryByIdList(java.lang.String)
	 */
	@Override
	public List<DLicence> queryByIdList(String strings) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.DLicenceDAOI#countById(java.lang.String)
	 */
	@Override
	public int countById(String id) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * @return the sessionFactory
	 */
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/**
	 * @param sessionFactory the sessionFactory to set
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

}
